﻿$(function () {

    function chatAppViewModel() {
        var self = this;

        self.userAlias = "Lamin Sanneh";

        self.listOfMessages = ko.observableArray([
            { sender: "Lamin Sanneh", message: "Hey is anyone here?" },
            { sender: "Lisa Sanneh", message: "Yh m here!" },
            { sender: "Siever Ali", message: "Yoh wad up?" }
        ]);

        self.sendButtonClicked = function () {
            var textMessage = $("#chatMessage").val();

            if (textMessage.length != 0) {
                self.listOfMessages.push({ sender: self.userAlias, message: textMessage });
            }
            return false;
        }

        self.listOfChatRooms = ko.observableArray([]);

        self.listOfUsers = ko.observableArray([]);

        self.updateRoomList = function () {
            //$.ajax({
            //    url: "/Api/Rooms/",
            //    type: "GET",
            //}).done(function (roomsList) {
            //    var arrayOfRooms = $.parseJSON(roomsList);
            //    self.listOfChatRooms.removeAll();
            //    $.each(arrayOfRooms, function (index, value) {
            //        self.listOfChatRooms.push(value);
            //    });                
            //});
        }

        self.updateRoomList();
    }

    ko.bindingHandlers.jqueryTabs = {
        update: function (element, valueAccessor) {
            var options = valueAccessor() || {};
            setTimeout(function () {
                $("#tabs").tabs(options).addClass("ui-tabs-vertical ui-helper-clearfix");
                $("#tabs li").removeClass("ui-corner-top").addClass("ui-corner-left");
            }, 400 );
        }
    };

    //ko.applyBindings(new chatAppViewModel());

});
